package com.alageek.study.api.impl;

import com.alageek.study.api.Iterator;
import com.alageek.study.entity.Book;
import com.alageek.study.entity.BookShelf;

public class BookShelfIterator implements Iterator {

    private BookShelf bookShelf;

    public BookShelfIterator(BookShelf bookShelf){
        this.bookShelf = bookShelf;
    }

    @Override
    public Boolean hasNext() {
        return bookShelf.getIndex()<bookShelf.getBooks().size();
    }

    @Override
    public Object next() {
        Book book = bookShelf.getBooks().get(bookShelf.getIndex());
        bookShelf.setIndex(bookShelf.getIndex()+1);
        return book;
    }
}
